﻿using System.Diagnostics;
using System.Drawing;
using Space.Library;

namespace Space.Model.Data
{
    public static class Board
    {
        public static readonly int Height = 800;
        public static readonly int Width = 1400;

        /// <summary>
        /// Size of each square on game board.
        /// </summary>
        public static int Ssize;

        public static float SsizeHalf;

        /// <summary>
        /// Pixels space around each spaceship.
        /// </summary>
        public static int ShipPadding;

        public static int BoardXMax;
        public static int BoardYMax;

        public static Point WindowSpaceToBoardSpace(int x, int y)
        {
            // Flip Y-axis
            y = BoardYMax - (y/Ssize);

            var point = new Point(x / Ssize, y);
            return point;
        }

        public static Point GetBoardCoords(Vector2D point)
        {
            var dest = new Point((int)(point.X / Ssize), (int)(point.Y / Ssize));
            return dest;
        }

        public static Vector2D GetShipPos(Point coords)
        {
            var point = new Vector2D(coords.X * Ssize + SsizeHalf, coords.Y * Ssize + SsizeHalf);
            return point;
        }

        public static void Init()
        {
            Ssize = 50;
            BoardXMax = Width/Ssize;
            BoardYMax = Height/Ssize;
            SsizeHalf = (float) Ssize/2;

            Debug.Assert(Width%Ssize == 0);
            Debug.Assert(Height%Ssize == 0);
            Debug.Assert(Ssize%5 == 0);
        }
    }
}
